<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html>
<head>
   	<title>${fns:getConfig('productName')}</title>
    <meta name="decorator" content="blank"/>
	<%@include file="/WEB-INF/view/include/comfile.jsp" %>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <!-- <script>if(window.top !== window.self){ window.top.location = window.location;}</script> -->
	
	<%@include file="/WEB-INF/view/include/jqGrid.jsp" %>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content  mod-bord">
                        <div class="jqGrid_wrapper">
                            <table id="table_list_1"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
	    function delDict(id){
			layer.confirm('确认删除元素:'+id, {
	    		   title: false, //不显示标题栏
			       offset: ['30%', '40%'],
			       btn: ['确认','取消'] //按钮
	    	}, function(){
	    		$.ajax({
					  url: '${ctx}/sys/dict/del',
					  dataType: 'json',
					  type: 'POST',
					  data:{
						  id:id
					  },
					  success: function (data) {
						  jQuery("#table_list_1").jqGrid("delRowData",id)
					  },
					  error: function (jqXHR, text, errorThrown) {
					      console.log(jqXHR + " " + text + " " + errorThrown);
					  }
				});
			  layer.closeAll();
	    	}, function(){
	    		closeBtn: 0;
	    	});
		};
    
        $(document).ready(function(){
			$.jgrid.defaults.styleUI="Bootstrap";

			$("#table_list_1").jqGrid({
				 url:'${ctx}/sys/dict/list',
				 datatype:"json",
				 mtype : "post",
				 height:'40%',
				 autowidth:true,
				 shrinkToFit:true,
				 treeGrid: true,
				 treeGridModel: 'adjacency',
				 defaultExpandLevel: 0,
				 ExpandColumn : 'lable',
				 expandOnLoad: true,
				 treeIcons: {leaf:'ui-icon-document-b'},
/* 				 rowNum:10,
				 rowList:[10,20,50], */
				 //multiselect:true,
				 //multiboxonly:false,
				 //multiselectWidth:60,
				 //toolbar:[true,"top"],
				 colNames:["id","lable","value","type","sort","description","操作"],
				 colModel:[
							{name:"id",index:"id",hidden:true,key:true},
						    {name:"lable",index:"lable",width:120},
						    {name:"value",index:"value",width:140},
						    {name:"type",index:"type",width:120},
						    {name:"sort",index:"sort",width:150},
						    {name:"description",index:"description",width:100},
						    {name:'actions', width:90, fixed:true, sortable:false, resizable:false, fixed:true,formatter: function(val, obj, row, act){  
					            	var actions = [];
					            		actions.push('&nbsp;<a href="${ctx}/sys/dict/form?id='+row.id+'&op=add" class="btnList" title="添加数据"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;&nbsp;');
					            		actions.push('<a href="${ctx}/sys/dict/form?id='+row.id+'&op=update" class="btnList" title="编辑数据"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;');  
						                actions.push('<a onclick="delDict('+row.id+')" href="javascript:void(0)" class="btnList" title="删除数据"><i class="fa fa-times"></i></a>');  
					            	return actions.join('');  
				        		}
						    }
						  ],
				 pager:"false",
				 viewrecords:true,
				 caption:"数据字典列表", 			  
				 hidegrid:false,
				 jsonReader: {    
                     root: "dataRows",    
                     repeatitems : false      
                 },
				 treeReader : {    
                     level_field: "level",
                     parent_id_field: "pid",    
                     leaf_field: "isLeaf",    
                     expanded_field: "expanded"   
                 },  
                 /* sortorder: "asc", */
                 rowNum : "-1",     // 显示全部记录
			 });

			
			$(window).bind("resize",function(){
				var width=$(".jqGrid_wrapper").width();
				$("#table_list_1").setGridWidth(width)
			})
		});
        
        
    </script>
</body>
</html>
